package com.milk.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.milk.system.common.result.PageResult;
import com.milk.system.common.result.Result;
import com.milk.system.model.form.MerchantsForm;
import com.milk.system.model.query.MerchantsPageQuery;
import com.milk.system.model.vo.MerchantsPageVO;
import com.milk.system.service.MerchantsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 商家信息表 前端控制器
 *
 * @author milk
 * @since 2024-05-02
 */
@Tag(name = "商家信息表接口")
@RestController
@RequestMapping("/api/business/merchantss")
@RequiredArgsConstructor
public class MerchantsController {

    private final MerchantsService merchantsService;

    @Operation(summary = "商家信息表分页列表")
    @GetMapping("/page")
    public PageResult<MerchantsPageVO> listPagedMerchantss(MerchantsPageQuery queryParams) {
        IPage<MerchantsPageVO> result = merchantsService.listPagedMerchantss(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增商家信息表")
    @PostMapping
    public Result saveMerchants(@RequestBody @Valid MerchantsForm formData) {
        boolean result = merchantsService.saveMerchants(formData);
        return Result.judge(result);
    }

    @Operation(summary = "商家信息表表单数据")
    @GetMapping("/{id}/form")
    public Result<MerchantsForm> getMerchantsForm(
            @Parameter(description = "商家信息表ID") @PathVariable Long id
    ) {
        MerchantsForm formData = merchantsService.getMerchantsFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改商家信息表")
    @PutMapping(value = "/{id}")
    public Result updateMerchants(@Parameter(description = "商家信息表ID") @PathVariable Long id,
                                  @RequestBody @Validated MerchantsForm formData) {
        boolean result = merchantsService.updateMerchants(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除商家信息表")
    @DeleteMapping("/{ids}")
    public Result deleteMerchantss(
            @Parameter(description = "商家信息表ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = merchantsService.deleteMerchantss(ids);
        return Result.judge(result);
    }
}
